package com.springcloud.feigndemo.controller

import org.springframework.core.io.FileSystemResource
import org.springframework.core.io.Resource
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.client.RestTemplate
import org.springframework.web.multipart.MultipartFile

@RestController
class LocalController {

    @GetMapping(value = 's')
    String t(@RequestParam String wd,@RequestParam String username,@RequestParam info)
    {

        '参数为:'+wd+',用户名:'+username+',info:'+info
    }

    @PostMapping(value = 'upload')
    String file(@RequestPart('file') MultipartFile file)
    {
        def tempFile = File.createTempFile('Springcloud-', file.originalFilename, new File('C:\\Users\\逆游的鱼\\Desktop\\tmp'))
        file.transferTo(tempFile)

        '写入成功'
    }


    @GetMapping(value = 'getImg',produces = MediaType.IMAGE_JPEG_VALUE)
    ResponseEntity<Resource > image(){

        def r= new FileSystemResource(new File('C:\\Users\\逆游的鱼\\Desktop\\tmp\\pic\\xie.jpg'))

        def headers=new HttpHeaders()

        headers.setContentType MediaType.IMAGE_JPEG

        ResponseEntity.ok().headers(headers).body(r)
    }

}
